package com.funmi.lizip.security.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.funmi.lizip.common.base.R;
import com.funmi.lizip.common.base.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        String msg = "注销成功";
        // 注销登录
        /*response.setStatus(ResultCode.LOGOUT_SUCCESS.getCode());
        response.setContentType("application/json;charset=UTF-8");

        //以Json格式返回
        R result = R.fail().code(ResultCode.LOGOUT_SUCCESS).message(msg);p[;pop
        response.getWriter().write(objectMapper.writeValueAsString(result));*/
    }
}
